package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.webservice.AttrsIn;
import com.chinanet.utils.webservice.ITMSWebService;

import java.util.HashMap;
import java.util.Map;

/**
 * ITMS_WebService_Imp_queryLanInfo
 * itms-ONU的网口状态查询
 * @author xuzhi
 *
 */
public class ITMS_WebService_Imp_queryLanInfo implements WorkInterFace {

	@Override
	public String getName() {
		return "ITMS-ONU的网口状态查询";
	}

	@Override
	public String getDesciption() {
		return "";
	}

	@Override
	public int getVersion() {
		return 0;
	}

	@Override
	public Attr[] getInAttrs() {
		Attr[] in=new Attr[3];
		in[0]=new Attr("ppp_usename","用户宽带账号(三个参数选填一个)", AttrType.TYPE_String,true);
		in[1]=new Attr("serial_number","设备序列号(三个参数选填一个)",AttrType.TYPE_String,true);
		in[2]=new Attr("logic_id","终端SN号(三个参数选填一个)",AttrType.TYPE_String,true);
		return in;
	}

	@Override
	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[11];
		out[0]=new Attr("ReturnCode", "0：成功；其它：失败", AttrType.TYPE_Int, true);
		out[1]=new Attr("return", "返回return", AttrType.TYPE_String, true);
		out[2]=new Attr("name", "LAN名称", AttrType.TYPE_String, true);
		out[3]=new Attr("connection_rate", "连接速率", AttrType.TYPE_String, true);
		out[4]=new Attr("status", "状态", AttrType.TYPE_String, true);
		out[5]=new Attr("accept_byte_count", "接收字节数(Kb)", AttrType.TYPE_String, true);
		out[6]=new Attr("send_byte_count", "发送字节数(Kb)", AttrType.TYPE_String, true);
		out[7]=new Attr("accept_package_count", "收包数", AttrType.TYPE_String, true);
		out[8]=new Attr("send_package_count", "发包数", AttrType.TYPE_String, true);
		out[9]=new Attr("log", "服务器返回的soapxml", AttrType.TYPE_String, true);
		out[10]=new Attr("Errormsg", "服务器返回的错误信息,当ReturnCode为0的时候就不必去读取", AttrType.TYPE_String, false);
		return out;
	}

	@Override
	public Map<String, Object> init(Map<String, Object> data) {
		AttrsIn attrsIn=new AttrsIn();
		ITMSWebService webService=new ITMSWebService();
		Map<String,Object> map=new HashMap<String, Object>();
		//Get into arguments
		attrsIn.setFunctionName("queryLanInfo");
		attrsIn.setRequestMessage("<logic_id>"+webService.dealString((String) data.get("logic_id"))+"</logic_id>" +
	            "<ppp_username>"+webService.dealString((String) data.get("ppp_username"))+"</ppp_username>" +
	            "<serial_number>"+webService.dealString((String) data.get("serial_number"))+"</serial_number>");
		//Get soapxml
		String returnXml=webService.WebServiceInit(attrsIn,1);
		String flag=webService.getPattern("return", returnXml);
		
		if(flag.length()>0){
			map.put("ReturnCode", 0);
			map.put("return", webService.getPattern("return", returnXml));
			map.put("name", webService.getPattern("name", returnXml));
			map.put("connection_rate", webService.getPattern("connection_rate", returnXml));
			map.put("status", webService.getPattern("status", returnXml));
			map.put("accept_byte_count", webService.getPattern("accept_byte_count", returnXml));
			map.put("send_byte_count", webService.getPattern("send_byte_count", returnXml));
			map.put("accept_package_count", webService.getPattern("accept_package_count", returnXml));
			map.put("send_package_count", webService.getPattern("send_package_count", returnXml));
			map.put("log", returnXml);
			map.put("Errormsg", "");
		}else{
			map.put("ReturnCode", 1);
			map.put("return", "");
			map.put("name", "");
			map.put("connection_rate", "");
			map.put("status", "");
			map.put("accept_byte_count", "");
			map.put("send_byte_count", "");
			map.put("accept_package_count", "");
			map.put("send_package_count", "");
			map.put("log", returnXml);
			map.put("Errormsg", "网元侧执行出错，处理请求失败");
		}
		
		return map;
	}

}
